package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.cache.GuiGuCache;
import com.atguigu.tingshu.common.config.redis.RedissonConfig;
import com.atguigu.tingshu.common.constant.RedisConstant;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

	@Autowired
	private BaseCategoryService baseCategoryService;
    @Autowired
    private RedissonConfig redissonConfig;


	/**
	 * TODO 将来需要将查询出来的数据缓存到redis中
	 * 查询所有的1,2,3级分类列表
	 * @return
	 */
	@Operation(summary = "查询所有的1,2,3级分类列表")
	@GetMapping("/category/getBaseCategoryList")

	public Result<List<JSONObject>> getBaseCategoryList(){

		List<JSONObject> list = baseCategoryService.getBaseCategoryList();

		return Result.ok(list);
	}

	/**
	 * 根据一级分类Id获取分类属性以及属性值
	 * @return
	 */
	@GetMapping("/category/findAttribute/{category1Id}")
	@Operation(summary = "根据一级分类Id获取分类属性以及属性值")

	public Result<List<BaseAttribute>> findAttribute(@PathVariable Long category1Id){

		List<BaseAttribute> baseAttributeList = baseCategoryService.findAttribute(category1Id);

		return Result.ok(baseAttributeList);
	}


	/**
	 * 根据三级分类Id 获取到分类信息,用于openfeign远程调用
	 * @param category3Id
	 * @return
	 */
	@Operation(summary = "根据三级分类Id 获取到分类信息,用于openfeign远程调用")
	@GetMapping("/category/getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getCategoryView(@PathVariable(name = "category3Id") Long category3Id){
		BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);

		return Result.ok(baseCategoryView);
	}


	/**
	 * 根据一级分类Id查询置顶7个三级分类列表
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类Id查询置顶7个三级分类列表")
	@GetMapping("/category/findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id){

		List<BaseCategory3> baseCategory3List = baseCategoryService.findTopBaseCategory3(category1Id);

		return Result.ok(baseCategory3List);
	}

	/**
	 * 查询1级分类下包含所有二级以及三级分类
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类id获取全部分类信息")
	@GetMapping("/category/getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getBaseCategoryList(@PathVariable Long category1Id){

		JSONObject jsonObject = baseCategoryService.getBaseCategoryListSearch(category1Id);

		return Result.ok(jsonObject);
	}


	/**
	 * 查询所有的一级分类信息
	 * @return
	 */
	@Operation(summary = "查询所有的一级分类信息")
	@GetMapping("/category/findAllCategory1")
	public Result<List<BaseCategory1>> findAllCategory1(){
		LambdaQueryWrapper<BaseCategory1> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.select(BaseCategory1::getId);
		List<BaseCategory1> list = baseCategoryService.list(queryWrapper);
		return Result.ok(list);
	}
}

